package com.star.spring.intercepter;

import com.baomidou.mybatisplus.extension.plugins.handler.MultiDataPermissionHandler;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.schema.Table;

@Slf4j
public class CustomDataPermissionHandler implements MultiDataPermissionHandler {
    @Override
    public Expression getSqlSegment(final Table table, final Expression where, final String mappedStatementId) {
        try {
            if (table.getName().equals("t_user")) {
                Expression sqlSegmentExpression = CCJSqlParserUtil.parseCondExpression("organ_id = 1");
                return new AndExpression(where, sqlSegmentExpression);
            }
        } catch (Exception e) {
            log.info(e.getMessage());
        }

        return null;
    }
}